/*   Copyright © 2009 Mark Gil Torres
 *
 *   This file is part of mtoolkit.
 *
 *   mtoolkit is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   any later version.
 *
 *   mtoolkit is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with mtoolkit.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "../include/real.h"
#define BOOST_TEST_MODULE Real test
#include <boost/test/included/unit_test.hpp>

using namespace mt;

BOOST_AUTO_TEST_CASE(constructor_test) {
  Real x1;
  Real x2(0);
  Integer x3("1234567890");
  Real x4(x3);
  BOOST_CHECK_EQUAL(x1,0);
  BOOST_CHECK_EQUAL(x1,x2);
  BOOST_CHECK_EQUAL(x4,1234567890);

  Integer x5("11223344556677889900");
  Real x6(x5);
  Real x7("11223344556677889900");
  BOOST_CHECK_EQUAL(x6,x7);
  Rational x8(1,10);
  Real x9("0.1");
  Real x10(x8);
  BOOST_CHECK_EQUAL(x9,x10);
  x10 = 1;
  BOOST_CHECK_EQUAL(x10,1);
  x9 = x8;
  Real x13(0.1);
  BOOST_CHECK_EQUAL(x9,x13);
//  x5 = "10.5";
//  BOOST_CHECK_EQUAL(x5,10.5);
  Real x11;
  x11 = x5;
  BOOST_CHECK_EQUAL(x11,x7);
  Real x12=x9;
  BOOST_CHECK_EQUAL(x12,0.1);
}

BOOST_AUTO_TEST_CASE(arithmetic_test) {
  Real x1(1.2);
  Real x2(2.4);
  Real x3(0.5);
  BOOST_CHECK_EQUAL((x1/x2),x3);
  BOOST_CHECK_EQUAL((x2/x1),2);
  Real x4(1);
  Real x5(2);
  Real x20(3.6);
  BOOST_CHECK_EQUAL((x4/x5),x3);
  BOOST_CHECK_EQUAL((x5/x4),2);
  BOOST_CHECK_EQUAL((x4-x5),-1);
  BOOST_CHECK_EQUAL((x5*x3),x4);
  BOOST_CHECK_EQUAL((x1+x2),x20);
  Integer x6(6);
  BOOST_CHECK_EQUAL((x6/x1),5);
  BOOST_CHECK_EQUAL((x6+x1),7.2);
  BOOST_CHECK_EQUAL((x6-x1),4.8);
  BOOST_CHECK_EQUAL((x6*x3),3);
  BOOST_CHECK_EQUAL((x5+x6),8);
  BOOST_CHECK_EQUAL((x5-x6),-4);
  BOOST_CHECK_EQUAL((x5*x6),12);
  BOOST_CHECK_EQUAL((x1/x6),0.2);
  Rational x7(1,2);
  BOOST_CHECK_EQUAL((x5+x7),2.5);
  BOOST_CHECK_EQUAL((x7+x5),2.5);
  BOOST_CHECK_EQUAL((x5-x7),1.5);
  BOOST_CHECK_EQUAL((x7-x5),-1.5);
  BOOST_CHECK_EQUAL((x5*x7),1);
  BOOST_CHECK_EQUAL((x7*x5),1);
  BOOST_CHECK_EQUAL((x5/x7),4);
  BOOST_CHECK_EQUAL((x7/x5),0.25);

  BOOST_CHECK_EQUAL((x5+0.5),2.5);
  BOOST_CHECK_EQUAL((0.5+x5),2.5);
  BOOST_CHECK_EQUAL((x5-0.5),1.5);
  BOOST_CHECK_EQUAL((0.5-x5),-1.5);
  BOOST_CHECK_EQUAL((x5*0.5),1);
  BOOST_CHECK_EQUAL((0.5*x5),1);
  BOOST_CHECK_EQUAL((x5/0.5),4);
  BOOST_CHECK_EQUAL((0.5/x5),0.25);
}

BOOST_AUTO_TEST_CASE(relational_test) {
  Real x1(0);
  Real x2(1.5);
  Real x3(1.50);
  Real x4(2);
  BOOST_CHECK_EQUAL((x1<x2),true);
  BOOST_CHECK_EQUAL((x2<x1),false);
  BOOST_CHECK_EQUAL((x2<x3),false);
  BOOST_CHECK_EQUAL((x1<=x2),true);
  BOOST_CHECK_EQUAL((x2<=x1),false);
  BOOST_CHECK_EQUAL((x2<=x3),true);
  BOOST_CHECK_EQUAL((x1>x2),false);
  BOOST_CHECK_EQUAL((x2>x1),true);
  BOOST_CHECK_EQUAL((x2>x3),false);
  BOOST_CHECK_EQUAL((x1>=x2),false);
  BOOST_CHECK_EQUAL((x2>=x1),true);
  BOOST_CHECK_EQUAL((x2>=x3),true);
  BOOST_CHECK_EQUAL((x1==x2),false);
  BOOST_CHECK_EQUAL((x2==x1),false);
  BOOST_CHECK_EQUAL((x2==x3),true);
}
